﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading;

namespace Envelope
{
    class Program
    {

        const int EnvelopesQuantity = 2;
        const int EnvelopesDimensions = 2;
        const string Exit = "exit";
        const string Beginning = "Envelope 0 is a sample envelope.\nType \"{0}\" for quit.";
        const string Envelope = "Enter Envelope {0} :";
        const string Side = "Side{0}:";
        const string Error = "Again!!!";


        static void Main(string[] args)
        {
            int yesNo = 0;
            bool canPlaced = true;
            string s = string.Empty;
            double[,] envelopes = new double[EnvelopesDimensions, EnvelopesQuantity];
            while (true)
            {
                Console.WriteLine(Beginning, Exit);
                for (int i = 0; i < EnvelopesQuantity && s != Exit; i++)
                {
                    Console.WriteLine(Envelope, i);
                    for (int j = 0; j < EnvelopesDimensions && s != Exit; j++)
                    {
                        Console.WriteLine(Side, j + 1);
                        s = Console.ReadLine();
                        while (!double.TryParse(s, out envelopes[i, j]) && s != Exit)
                        {
                            if (s != string.Empty) Console.WriteLine(Error);
                            s = Console.ReadLine();
                        }
                    }
                }
                if (s == Exit)
                {
                    break;
                }

                for (int i = 1; i < EnvelopesQuantity; i++)
                {
                    for (int j = 0; j < EnvelopesDimensions; j++)
                    {
                        if (envelopes[0,j] < envelopes[i,j])
                        {
                            canPlaced = false;
                        }
                    }
                }
                Console.WriteLine("These envenlopes can{0} be placed in Envelope 0!", (canPlaced)? string.Empty : "NOT");
                Console.WriteLine("Do you want to repeat this? (y/n)");
                yesNo = Console.Read();
                if (yesNo != 'y')
                {
                    if (yesNo != 'n')
                    {
                        Console.WriteLine("ErRoR!");
                    }
                    break;
                }
                canPlaced = true;
                Console.Clear();
            }
            

        }
    }
}
